export function dateToRef(dateStr) {
  const postDate = new Date(dateStr);
  const nowDate = new Date();
  const diff = Math.floor((nowDate - postDate) / 1000);
  if (diff < 60) {
    return `${diff}秒前发布`;
  } else if (diff < 60 * 60) {
    return `${Math.floor(diff / 60)}分钟前发布`;
  } else if (diff < 60 * 60 * 24) {
    return `${Math.floor(diff / 60 / 24)}小时前发布`;
  } else {
    return `${postDate.getFullYear()}年-${(
      "0" +
      (postDate.getMonth() + 1)
    ).slice(-2)}月-${("0" + (postDate.getDate() + 1)).slice(-2)}日`;
  }
}
